<?php

namespace App\Http\Controllers\Page\Admin;

use App\Facades\DeviceService;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class DeviceController extends Controller
{
    public function index(Request $request)
    {
        if($request->status == '缺水')
        {
            $status = \App\Models\Device::HYDROPENIA;
        }else if($request->status == '检修'){
             $status = \App\Models\Device::OVERHAUL;
        }else{
            $status = '';
        }
        
        $deviceCode = $request->deviceCode;
        $deviceCode = str_replace('%', '\%', $deviceCode);
        $deviceCode = str_replace('_', '\_', $deviceCode);

        $deviceList = DeviceService::getDeviceRecordLlist($deviceCode, $status);
        return view('admin/equip_info')->with([
            'deviceList' => $deviceList,
            'deviceCode' => $request->deviceCode,
            'status' => $request->status,
            ]);
    }

    public function history(Request $request)
    {
        $deviceInfos = DeviceService::getDeviceInfoListByDeviceCode($request->deviceId);
        return view('admin/equip_notes')->with(['deviceInfos' => $deviceInfos]);
    }

}
